package com.yanqu.road.server.cmd.tradewar;

import com.yanqu.road.pb.cross.tradewar.CrossTradeWarProto;
import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.tradewar.CrossTradeWarMgr;
import com.yanqu.road.server.manager.union.activitygroup.Cross2UnionActivityGroupMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_CROSS_TRADE_WAR_WANTED_RANK_TOP, desc = "获取通缉榜榜首")
public class CrossTradeWarGetWantedRankTopCmd extends CrossUnionCommand {
    private int activityId;
    private long reqUserId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossTradeWarProto.CrossTradeWarWantedRankTopReqMsg reqMsg = CrossTradeWarProto.CrossTradeWarWantedRankTopReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        reqUserId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossTradeWarProto.CrossTradeWarWantedRankTopRespMsg.Builder respMsg = CrossTradeWarProto.CrossTradeWarWantedRankTopRespMsg.newBuilder();
        respMsg.setRet(0);
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, reqUserId);
        RankProto.RankTempMsg.Builder rankMsg = CrossTradeWarMgr.getTradeWarWantedRankTop(activityId,groupId);
        if(null != rankMsg) {
            respMsg.setRankTemp(rankMsg);
        }
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.U_CROSS_TRADE_WAR_WANTED_RANK_TOP, respMsg);
        MessageHelper.sendPacket(serverId, reqUserId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
